#include <stdio.h>
#include <stdlib.h>

//每个时间点；是起始时间，还是终止时间；及其对应的结束时间
typedef struct point_t
{
int time;
int is_start;
int end_time;//若is_start为1，end_time写对应的时间；若is_start为0，end_time为-1
} point;

//升序排列，若时间相同，则为终止时间的时间点排在前面
int compare(const void* a, const void* b)
{
if ((*(point*)a).time != (*(point*)b).time)
    return (*(point*)a).time > (*(point*)b).time;
else 
    return (*(point*)a).is_start < (*(point*)b).is_start;//这里得用小于
}

void process(point* points, const int n)
{
//排序
qsort(points, n, sizeof(point), compare);
//最多n/2个教室
int classrooms[n/2];
int count = 0;
classrooms[count++] = points[0].end_time;
printf("[%d, %d) in class %d\n", points[0].time, points[0].end_time, count);
int i;
int j;
for (i = 1; i < n; i++)
{
    if (points[i].is_start == 1)
    {
    for (j = 0; j < count; j++)
    {
    if (classrooms[j] <= points[i].time)
    {
    classrooms[j] = points[i].end_time;
    printf("[%d, %d) in class %d\n", points[i].time, points[i].end_time, j+1);
    break;
    }
    }
    if (j == count)
    {
    classrooms[count++] = points[i].end_time;
    printf("[%d, %d) in class %d\n", points[i].time, points[i].end_time, count);
    }
    }
}
printf("%d in total.\n", count);
}

int main()
{
int rows;
scanf("%d", &rows);
//2*rows个点
point* points = (point*)malloc(2*rows*sizeof(point));
//point p;
int n = rows;
//point p;
int start_time;
int end_time;
while (rows--)
{
    int id = n - rows - 1;
    scanf("%d%d", &start_time, &end_time);
    point p1;
    p1.is_start = 1;
    p1.time = start_time;
    p1.end_time = end_time;
    points[2*id] = p1;    
    
    point p2;
    p2.is_start = 0;
    p2.time = end_time;
    p2.end_time = -1;
    points[2*id + 1] = p2;
}
process(points, 2*n);
free(points);
return 0;
}